<?php
/**
 * Description of cmsValidatedFile
 *
 * @author piotr
 */
class cmsValidatedFile extends sfValidatedFile
{
  private $savedFilename = null;

  // Override sfValidatedFile's save method
  public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777)
  {    
    $this->savedFilename = Cms::slugify(basename($this->originalName, $this->getExtension()));    
    
    $saved = parent::save($this->savedFilename, $fileMode, $create, $dirMode);
     
    foreach(sfConfig::get('app_image_sizes') as $size)
    {
      $thumbnail = new sfThumbnail($size['x'], $size['y']);

      $thumbnail->loadFile($this->savedName);

      $thumbnail->save($this->savedName . '_' . $size['sufix'] . $this->getExtension());          
    }
      
    return $saved;
  }
}
?>